<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="维修单号" prop="applyNo">
        <el-input v-model="queryParams.applyNo" placeholder="请输入维修单号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="车牌号" prop="carPlateNo">
        <el-input v-model="queryParams.carPlateNo" placeholder="请输入车牌号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="维修状态" prop="repairStatus">
        <el-select v-model="queryParams.repairStatus" placeholder="请选择维修状态" clearable size="small">
          <el-option v-for="dict in dict.type.maintenance_state" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['maintenance:repair:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['maintenance:repair:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
          @click="handleExport" v-hasPermi="['maintenance:repair:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="repairList" @selection-change="handleSelectionChange">
      <el-table-column label="维修单号" align="center" prop="applyNo" />
      <el-table-column label="车牌号" align="center" prop="carPlateNo" />
      <el-table-column label="车架号" align="center" prop="vinNo" />
      <el-table-column label="车辆状态" align="center" prop="carStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_status" :value="scope.row.carStatus" />
        </template>
      </el-table-column>
      <el-table-column label="维修状态" align="center" prop="repairStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.maintenance_state" :value="scope.row.repairStatus" />
        </template>
      </el-table-column>
      <el-table-column label="维修开始时间" align="center" prop="repairStartDate" width="180"/>
      <el-table-column label="维修结束时间" align="center" prop="repairEndDate" width="180"/>
      <el-table-column label="维修厂名称" align="center" prop="serviceName" />
      <el-table-column label="记录人" align="center" prop="operator" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text"  @click="handleUpdate(scope.row)" v-if="scope.row.repairStatus<3"
            v-hasPermi="['maintenance:repair:edit']">修改</el-button>
          <el-button size="mini" type="text"  @click="handleFeedback(scope.row)" v-if="scope.row.repairStatus<3"
            v-hasPermi="['maintenance:repair:feedback']">反馈</el-button>
          <el-button size="mini" type="text"  @click="handleDelete(scope.row)" v-if="scope.row.repairStatus<3"
            v-hasPermi="['maintenance:repair:remove']">删除</el-button> -->
          <el-button size="mini" type="text"  @click="handleDetails(scope.row)" icon="el-icon-search"
            v-hasPermi="['maintenance:repair:query']">详情</el-button>

            <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
               v-if="scope.row.repairStatus<3"
              v-hasPermi="['maintenance:repair:edit', 'maintenance:repair:feedback', 'maintenance:repair:remove']">
                <span class="el-dropdown-link">
                    <i class="el-icon-d-arrow-right el-icon--right"></i>更多
                </span>
                <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="edit" icon="el-icon-edit" v-hasPermi="['maintenance:repair:edit']"  v-if="scope.row.repairStatus<3">修改</el-dropdown-item>
                    <el-dropdown-item command="feedback"  icon="el-icon-edit" v-hasPermi="['maintenance:repair:feedback']" v-if="scope.row.repairStatus<3">反馈</el-dropdown-item>
                    <el-dropdown-item command="remove"  icon="el-icon-delete" v-hasPermi="['maintenance:repair:remove']" v-if="scope.row.repairStatus<3">删除</el-dropdown-item>
                </el-dropdown-menu>
            </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改车辆维修对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="车牌号" prop="carPlateNo">
              <!-- <el-input v-model="form.carPlateNo" placeholder="请输入车牌号" /> -->
              <el-input v-model="form.carPlateNo" placeholder="请选择车辆" clearable :style="{width: '100%'}" :readonly="true">
                <el-button slot="append" icon="el-icon-search" @click="showCarBox=true"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="车架号" prop="vinNo">
              <el-input v-model="form.vinNo" placeholder="请输入车架号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆状态">
              <el-select v-model="form.carStatus" placeholder="请选择车辆状态" clearable size="small">
                <el-option v-for="dict in dict.type.car_status" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="维修开始时间" prop="repairStartDate">
              <el-date-picker clearable size="small" v-model="form.repairStartDate" type="datetime"
                format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择维修开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="维修结束时间" prop="repairEndDate">
              <el-date-picker clearable size="small" v-model="form.repairEndDate" type="datetime"
                format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择维修结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="故障描述" prop="faultDesc">
              <el-input v-model="form.faultDesc" type="textarea" placeholder="请输入故障描述" :maxlength="100" show-word-limit
                :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="维修厂名称" prop="serviceName">
              <el-input v-model="form.serviceName" placeholder="请输入维修厂名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维修厂报价" prop="repairShopQuotation">
              <el-input v-model="form.repairShopQuotation" placeholder="请输入维修厂报价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="维修内容">
              <el-input v-model="form.repairContent" type="textarea" placeholder="请输入维修内容" :maxlength="100"
                show-word-limit :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="用户支付金额" prop="userPay">
              <el-input v-model="form.userPay" placeholder="请输入用户支付金额"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="平台支付金额" prop="platformPay">
              <el-input v-model="form.platformPay" placeholder="请输入平台支付金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="保险支付金额" prop="insurancePay">
              <el-input v-model="form.insurancePay" placeholder="请输入保险支付金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总金额">
              <el-input v-model="totalPay" placeholder="自动计算" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="是否提供备用车" prop="isSpareCar">
              <!-- <el-input v-model="form.isSpareCar" placeholder="请输入是否提供备用车" /> -->
              <el-radio-group v-model="form.isSpareCar">
                <el-radio v-for="dict in dict.type.business_yes_no" :key="dict.value" :label="parseInt(dict.value)">
                  {{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备用车车牌号" prop="spareCarNo" v-if="form.isSpareCar==1">
              <el-input v-model="form.spareCarNo" placeholder="请输入备用车车牌号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="旧件名称" prop="oldItems">
              <el-input v-model="form.oldItems" placeholder="请输入旧件名称" />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="submitBtnLoading">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

   <!-- 详情对话框 -->
    <el-dialog title="维修记录详情" :visible.sync="detailsOpen" width="900px" append-to-body>
      <MmvTitle title="维修车辆"></MmvTitle>
      <el-form label-width="120px">
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="车牌号">{{form.carPlateNo}}</el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="车架号">{{form.vinNo}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆状态">
              <dict-tag :options="dict.type.car_status" :value="form.carStatus" />
              <!-- <el-select v-model="form.carStatus" placeholder="请选择车辆状态" clearable size="small">
                <el-option v-for="dict in dict.type.car_status" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select> -->
            </el-form-item>
          </el-col>
        </el-row>
        </el-form>
        <MmvTitle title="维修信息"></MmvTitle>
        <el-form label-width="120px">
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="维修开始时间">{{form.repairStartDate}}</el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="故障描述">
              <el-input v-model="form.faultDesc" type="textarea" placeholder="无" :maxlength="100" show-word-limit
                :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}" :readonly="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="维修厂名称">{{form.serviceName}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维修厂报价">{{form.repairShopQuotation}}</el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="维修内容">
              <el-input v-model="form.repairContent" type="textarea" placeholder="请输入维修内容" :maxlength="100"
                show-word-limit :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"  :readonly="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="用户支付金额" prop="userPay">{{form.userPay}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="平台支付金额"  prop="platformPay">{{form.platformPay}}</el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="保险支付金额" prop="insurancePay">{{form.insurancePay}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总金额" prop="totalPay">{{totalPay}}</el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="是否提供备用车">
              <!-- <el-radio-group v-model="form.isSpareCar" >
                <el-radio v-for="dict in dict.type.business_yes_no" :key="dict.value" :label="parseInt(dict.value)" :readonly="true">
                  {{dict.label}}
                </el-radio>
              </el-radio-group> -->
              <dict-tag :options="dict.type.business_yes_no" :value="form.isSpareCar" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备用车车牌号"  v-if="form.isSpareCar==1">{{form.spareCarNo}}</el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="旧件名称" >{{form.oldItems}}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <MmvTitle title="反馈信息"></MmvTitle>
      <el-form label-width="120px">
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="维修结束时间"  >{{form.repairEndDate}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否已结算" prop="settlementStatus">
              <!-- <el-radio-group v-model="form.settlementStatus">
                <el-radio v-for="dict in dict.type.business_yes_no" :key="dict.value" :label="parseInt(dict.value)" :readonly="true">
                  {{dict.label}}
                </el-radio>
              </el-radio-group> -->
              <dict-tag :options="dict.type.business_yes_no" :value="form.settlementStatus" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="反馈意见" prop="repairFeedback">
              <el-input v-model="form.repairFeedback" type="textarea" placeholder="请输入反馈意见" :maxlength="100" show-word-limit :readonly="true"
                :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 维修反馈对话框 -->
    <el-dialog title="车辆维修反馈" :visible.sync="feedbackOpen" width="900px" append-to-body>
      <el-form ref="feedbackform" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="维修结束时间" prop="repairEndDate">
              <!-- {{new Date().getTime()}} -->
              <!-- {{new Date(form.repairStartDate).getTime()}} -->
              <!-- {{new Date(form.repairStartDate).getTime()}} -->
              <el-date-picker  :picker-options="{disabledDate: data=> new Date(data).getTime() < new Date(form.repairStartDate).getTime()}" clearable size="small" v-model="form.repairEndDate" type="datetime"
                format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择维修结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否已结算" prop="settlementStatus">
              <el-radio-group v-model="form.settlementStatus">
                <el-radio v-for="dict in dict.type.business_yes_no" :key="dict.value" :label="parseInt(dict.value)">
                  {{dict.label}}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="24">
            <el-form-item label="反馈意见" prop="repairFeedback">
              <el-input v-model="form.repairFeedback" type="textarea" placeholder="请输入反馈意见" :maxlength="100" show-word-limit
                :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="feedback">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!-- <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div> -->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
            @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <select-car v-model="showCarBox" @success="selectCarInfo"></select-car>
  </div>
</template>

<script>
  import {
    listRepair,
    getRepair,
    delRepair,
    addRepair,
    updateRepair,
    exportRepair,
    importTemplate
  } from "@/api/maintenance/repair";
  import {
    getToken
  } from "@/utils/auth";
  import MmvTitle from '@/components/MmvUI/MmvTitle.vue';
  import selectCar from "../../components/selectCar.vue";
  export default {
    name: "Repair",
    dicts: ['car_status', 'maintenance_state', 'business_yes_no'],
    components: {
        MmvTitle,
        selectCar
    },
    computed: {
      totalPay() {
        return (Number(this.form.userPay)+Number(this.form.platformPay)+Number(this.form.insurancePay)).toFixed(2)
      }
    },
    data() {
      return {
        submitBtnLoading: false,
        showCarBox:false,
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 车辆维修表格数据
        repairList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        feedbackOpen: false,
        detailsOpen: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          applyNo: null,
          carPlateNo: null,
          repairStatus: null,
        },
        // 用户导入参数
        upload: {
          // 是否显示弹出层
          open: false,
          // 弹出层标题
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: {
            Authorization: "Bearer " + getToken()
          },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/maintenance/repair/import"
        },
        // 表单参数
        form: {
          isSpareCar: 2,
        },
        // 表单校验
        rules: {
          carPlateNo: [{
            required: true,
            message: '车牌号不能为空',
            trigger: 'change'
          }],
          repairStartDate: [{
            required: true,
            message: '维修开始时间不能为空',
            trigger: 'change'
          }],
          repairEndDate: [{
            required: true,
            message: '维修结束时间不能为空',
            trigger: 'change'
          }],
          faultDesc: [{
            required: true,
            message: '故障描述不能为空',
            trigger: 'change'
          }],
          serviceName: [{
            required: true,
            message: '维修厂名称不能为空',
            trigger: 'change'
          }],
          repairShopQuotation: [
            {required: true,message: '维修厂报价不能为空',trigger: 'change'},
            {validator(rule, value, callback){
              if (!Number(value)){
                callback(new Error('价格错误'))
              }
              if (Number(value)<0){
                 callback(new Error('价格错误'))
              }
              return callback();
            }},
          ],
          repairContent: [{
            required: true,
            message: '维修内容不能为空',
            trigger: 'change'
          }],
          userPay: [{
            required: true,
            message: '用户支付金额不能为空',
            trigger: 'change'
          },
          {validator(rule, value, callback){
              if (!Number(value)){
                callback(new Error('价格错误'))
              }
              if (Number(value)<0){
                 callback(new Error('价格错误'))
              }
              return callback();
            }},],
          platformPay: [{
            required: true,
            message: '平台支付金额不能为空',
            trigger: 'change'
          },{validator(rule, value, callback){
              if (!Number(value)){
                callback(new Error('价格错误'))
              }
              if (Number(value)<0){
                 callback(new Error('价格错误'))
              }
              return callback();
            }},],
          totalPay: [{
            required: true,
            message: '总金额不能为空',
            trigger: 'change'
          },{validator(rule, value, callback){
              if (!Number(value)){
                callback(new Error('价格错误'))
              }
              if (Number(value)<0){
                 callback(new Error('价格错误'))
              }
              return callback();
            }},],
          insurancePay: [{
            required: true,
            message: '保险支付金额',
            trigger: 'change'
          },{validator(rule, value, callback){
              if (!Number(value)){
                callback(new Error('价格错误'))
              }
              if (Number(value)<0){
                 callback(new Error('价格错误'))
              }
              return callback();
            }},],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询车辆维修列表 */
      getList() {
        this.loading = true;
        listRepair(this.queryParams).then(response => {
          this.repairList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.feedbackOpen= false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          applyNo: null,
          carId: null,
          carPlateNo: null,
          vinNo: null,
          carStatus: 0,
          repairStatus: 0,
          repairStartDate: null,
          repairEndDate: null,
          faultDesc: null,
          serviceName: null,
          deptId: null,
          operator: null,
          delFlag: null,
          repairShopQuotation: null,
          repairContent: null,
          userPay: null,
          platformPay: null,
          insurancePay: null,
          totalPay: null,
          isSpareCar: 2,
          createBy: null,
          spareCarNo: null,
          oldItems: null,
          createTime: null,
          updateBy: null,
          repairFeedback: null,
          remark: null,
          updateTime: null,
          tenantId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加车辆维修";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getRepair(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改车辆维修";
        });
      },
      /** 反馈按钮操作 */
      handleFeedback(row) {
        this.reset();
        const id = row.id || this.ids
        getRepair(id).then(response => {
          this.form = response.data;
          this.feedbackOpen = true;
        });
      },
      /** 详情按钮操作 */
      handleDetails(row) {
        this.reset();
        const id = row.id || this.ids
        getRepair(id).then(response => {
          this.form = response.data;
          this.detailsOpen = true;
        });
      },
              // 更多操作触发
        handleCommand(command, row) {
            switch (command) {
                case "edit":
                    this.handleUpdate(row);
                    break;
                case "feedback":
                    this.handleFeedback(row);
                    break;
                case "remove":
                    this.handleDelete(row);
                    break;
                default:
                    break;
            }
        },
      selectCarInfo(car){
        this.showCarBox=false;
        if(car){
          this.form.carId=car.carId;
          this.form.carPlateNo=car.carNo;
        }
      },
      /** 提交按钮 */
      submitForm() {
        this.submitBtnLoading = true;
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateRepair(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addRepair(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
        setTimeout(()=> {
          this.submitBtnLoading = false;
        },2e3)
      },
      /** 反馈按钮 */
      feedback() {
        this.$refs["feedbackform"].validate(valid => {
          if (valid) {
            let data={
              ...this.form,
              repairStatus:3
            }
              updateRepair(data).then(response => {
                this.$modal.msgSuccess("反馈成功");
                this.feedbackOpen = false;
                this.getList();
              });
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id // || this.ids;
        this.$modal.confirm('是否确认删除数据项？').then(function() {
          return delRepair(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "维修单导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        importTemplate().then(response => {
          this.$download.name(response.msg);
        });
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, "导入结果", {
          dangerouslyUseHTMLString: true
        });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有车辆维修数据项？').then(() => {
          this.exportLoading = true;
          return exportRepair(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };
</script>
<style scoped="scoped">
  /deep/ .el-date-editor.el-input,
  .el-date-editor.el-input__inner{
    width: 100% !important;
  }
</style>
